# -*- coding: utf-8 -*-
"""
# --------------------------------------------------------
# @Author : Pan
# @E-mail :
# @Date   : 2025-05-19 10:51:33
# @Brief  :
# --------------------------------------------------------
"""
import glob
from importlib import import_module
from os.path import basename, dirname, isfile, join


def include_router(app, **kwargs):
    """
    导入路由,include_router必须放在__init__中
    :param app:
    :param kwargs:
    :return:
    """
    modules = glob.glob(join(dirname(__file__), '*.py'))
    modules = [basename(f)[:-3] for f in modules if isfile(f) and not f.endswith('__init__.py')]
    package = __name__  # app.api
    for m in modules:
        try:
            app.include_router(import_module('.{}'.format(m), package=package).router)
            print("router include : {}.{}".format(package, m))
        except Exception as e:
            print("is not  router : {}.{}".format(package, m))
